import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;

public class WeatherData {
	private final List<ActionListener> actionListeners;
	private float temperature;
	private float humidity;
	private float pressure;
	
	public WeatherData() {
		actionListeners= new ArrayList<>();
	}
	public void addActionListener(ActionListener o){{
		actionListeners.add(o);
	}}
	public void removeActionListener(ActionListener o) {
		actionListeners.add(o);
	}
	public  void processEvent(ActionEvent o){
		for(ActionListener actionListener: actionListeners){
			actionListener.actionPerformed(o);
		}
	}

	public void measurementsChanged() {
		// notifyObservers();
		processEvent(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null));
	}
	
	public void setMeasurements(float temperature, float humidity, float pressure) {
		this.temperature = temperature;
		this.humidity = humidity;
		this.pressure = pressure;
		measurementsChanged();
	}

	public float getTemperature() {
		return temperature;
	}
	
	public float getHumidity() {
		return humidity;
	}
	
	public float getPressure() {
		return pressure;
	}

}




// package headfirst.designpatterns.observer.weather;
// import java.util.*;

// public class WeatherData implements Subject {
// 	private List<Observer> observers;
// 	private float temperature;
// 	private float humidity;
// 	private float pressure;
	
// 	public WeatherData() {
// 		observers = new ArrayList<Observer>();
// 	}
	
// 	public void registerObserver(Observer o) {
// 		observers.add(o);
// 	}
	
// 	public void removeObserver(Observer o) {
// 		observers.remove(o);
// 	}
	
// 	public void notifyObservers() {
// 		for (Observer observer : observers) {
// 			observer.update(temperature, humidity, pressure);
// 		}
// 	}
	
// 	public void measurementsChanged() {
// 		notifyObservers();
// 	}
	
// 	public void setMeasurements(float temperature, float humidity, float pressure) {
// 		this.temperature = temperature;
// 		this.humidity = humidity;
// 		this.pressure = pressure;
// 		measurementsChanged();
// 	}

// 	public float getTemperature() {
// 		return temperature;
// 	}
	
// 	public float getHumidity() {
// 		return humidity;
// 	}
	
// 	public float getPressure() {
// 		return pressure;
// 	}

// }
